home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / HOSTRSET.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  5KB  |  123 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    h o s t r s e t . c                                             */
  3. /*                                                                    */
  4. /*    Clear host status information for UUPC/extended                 */
  5. /*                                                                    */
  6. /*    Copyright (c) 1989-1993, Andrew H. Derbyshire                   */
  7. /*    Copyright (c) 1992, Mitch Mitchell                              */
  8. /*--------------------------------------------------------------------*/
  9.  
  10. /*--------------------------------------------------------------------*/
  11. /*                        System include files                        */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. /*--------------------------------------------------------------------*/
  19. /*                    UUPC/extended include files                     */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. #include "lib.h"
  23. #include "hlib.h"
  24. #include "hostable.h"
  25. #include "hostatus.h"
  26. #include "hostrset.h"
  27. #include "security.h"
  28. #include "timestmp.h"
  29.  
  30. /*--------------------------------------------------------------------*/
  31. /*        Define current file name for panic() and printerr()         */
  32. /*--------------------------------------------------------------------*/
  33.  
  34. currentfile();
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*       H o s t R e s e t                                            */
  38. /*                                                                    */
  39. /*       Reset status information for one or more hosts               */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. void HostReset( const char *name )
  43. {
  44.    boolean firsthost = TRUE;
  45.    struct HostTable *host;
  46.    char fname[FILENAME_MAX];
  47.    FILE *stream;
  48.    unsigned short len1 = strlen(compilep );
  49.    unsigned short len2 = strlen(compilev );
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*         Get the file name for the status file and open it          */
  53. /*--------------------------------------------------------------------*/
  54.  
  55.    mkfilename( fname, E_spooldir, DCSTATUS );
  56.  
  57.  
  58.    if ((stream  = FOPEN(fname , "w", BINARY_MODE)) == NULL)
  59.    {
  60.       printmsg(1,"HostReset: Unable to open host status file");
  61.       printerr( fname );
  62.       panic();                /* Critical error if unable to write   */
  63.       return;
  64.    } /* if */
  65.  
  66. /*--------------------------------------------------------------------*/
  67. /*                 Write header information for file                  */
  68. /*--------------------------------------------------------------------*/
  69.  
  70.    fwrite( &len1, sizeof len1, 1, stream );
  71.    fwrite( &len2, sizeof len2, 1, stream );
  72.    fwrite( compilep , 1, len1, stream);
  73.    fwrite( compilev , 1, len2, stream);
  74.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  75.  
  76. /*--------------------------------------------------------------------*/
  77. /*     Now spin through the hosts and write out their information     */
  78. /*--------------------------------------------------------------------*/
  79.  
  80.    while  ((host = nexthost( firsthost )) != BADHOST)
  81.    {
  82.       len1 = strlen( host->hostname );
  83.       len2 = sizeof *(host->hstats);
  84.  
  85.       firsthost = FALSE;
  86.  
  87.       fwrite( &len1, sizeof len1, 1, stream );
  88.       fwrite( &len2, sizeof len2, 1, stream );
  89.       fwrite( host->hostname , sizeof host->hostname[0], len1, stream);
  90.  
  91. /*--------------------------------------------------------------------*/
  92. /*                    Clear this host if requested                    */
  93. /*--------------------------------------------------------------------*/
  94.  
  95.       if ( (name == NULL) || equal(name,host->hostname) )
  96.       {
  97.           host->hstats->calls     = 0l;  /* Total number of calls to host       */
  98.           host->hstats->connect   = 0l;  /* Total length of connections to host */
  99.           host->hstats->fsent     = 0l;  /* Total files sent to this host       */
  100.           host->hstats->freceived = 0l;  /* Total files received from this host */
  101.           host->hstats->bsent     = 0l;  /* Total bytes sent to this host       */
  102.           host->hstats->breceived = 0l;  /* Total bytes received from this host */
  103.           host->hstats->errors    = 0l;  /* Total transmission errors noted     */
  104.           host->hstats->packets   = 0l;  /* Total packets exchanged             */
  105.       }
  106.  
  107.       host->hstats->save_hstatus = host->hstatus;
  108.       fwrite( host->hstats , len2, 1,  stream);
  109.    }
  110.  
  111. /*--------------------------------------------------------------------*/
  112. /*         Make we sure got end of file and not an I/O error          */
  113. /*--------------------------------------------------------------------*/
  114.  
  115.    if (ferror( stream ))
  116.    {
  117.       printerr( fname );
  118.       clearerr( stream );
  119.    }
  120.    fclose( stream );
  121.  
  122. } /* HostReset */
  123.